package com.lut.edu.apm.commodityCenter.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

/**
 * 超市商品库存
 *
 * @author Zhao Suzhen
 */
@Data
@AllArgsConstructor
@TableName(value = "t_commodity_info")
public class CommodityOrder {
    @TableId(type = IdType.INPUT, value = "barcode")
    private String barcode;
    @TableField(value = "product_name")
    private String productName;
    @TableField(value = "product_item")
    private String productItem;
    private String brand;
    private String company;
    private String spec;
    @TableField(value = "origin_country")
    private String originCountry;
    @TableField(value = "product_note")
    private String productNote;
    @TableField(value = "price_b")
    private long priceB;
    @TableField(value = "price_a")
    private long priceA;
    @TableField(value = "price_d")
    private long priceD;
    private int reserve;
    private String area;
    private String status = "1";
    @TableField(value = "gmt_created")
    private Timestamp gmtCreated;
    @TableField(value = "gmt_modified")
    private Timestamp gmtModified;

    public boolean isEmpty() {
        if (null == this.barcode || this.barcode.isEmpty()) {
            return true;
        }
        if (null == this.productName || this.productName.isEmpty()) {
            return true;
        }
        return false;
    }

    public CommodityOrder(String barcode, String productName, String brand, String company, String spec,
                          String originCountry, String productNote, String priceB, String priceA, String priceD) {
        this.barcode = barcode;
        this.productName = productName;
        this.brand = brand;
        this.company = company;
        this.spec = spec;
        this.originCountry = originCountry;
        this.productNote = productNote;
        this.priceB = Math.round(Double.parseDouble(priceB) * 100);
        this.priceA = Math.round(Double.parseDouble(priceA) * 100);
        this.priceD = Math.round(Double.parseDouble(priceD) * 100);
        this.gmtCreated = new Timestamp(System.currentTimeMillis());
    }

    public CommodityOrder() {
        this.gmtCreated = new Timestamp(System.currentTimeMillis());
    }

}
